package github.flandre.examplemod.core.init.event;


import com.google.common.base.Objects;
import github.flandre.examplemod.common.guiblock.GuiBlockInit;
import github.flandre.examplemod.common.world.ExampleConfigFeature;
import github.flandre.examplemod.core.init.BlockInit;
import it.unimi.dsi.fastutil.objects.Object2ShortAVLTreeMap;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.placement.AtSurfaceWithExtraConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.placement.TopSolidRangeConfig;
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException;

import java.util.List;
import java.util.function.Supplier;

@Mod.EventBusSubscriber
public class OreGenerationEvent {
    @SubscribeEvent
    public static void generateOres(final BiomeLoadingEvent event)
    {
        //在地狱和雨林不会生成
        if(!(event.getCategory().equals(Biome.Category.NETHER) ||
        event.getCategory().equals(Biome.Category.THEEND)))
        {
            BiomeGenerationSettingsBuilder generation = event.getGeneration();
            //生成 地下 矿物
            generation.withFeature(GenerationStage.Decoration.UNDERGROUND_DECORATION,
                    Feature.ORE.withConfiguration(
                            new OreFeatureConfig(
                                    OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,//在石头层中生成
                                    GuiBlockInit.EXAMPLE_BLOCK.get().getDefaultState(),//生成的方块
                                    20//矿脉生成矿物的最大数量
                            )
                    ).withPlacement(Placement.RANGE.configure(
                            new TopSolidRangeConfig(
                                    //最小高度 偏差 最大高度
                                    15,5,60
                            ))).square().func_242731_b(20)//一个区块最大生成矿脉数
            );
        }

        //生成树
        if(event.getCategory().equals(Biome.Category.PLAINS))
        {
            List<Supplier<ConfiguredFeature<?, ?>>> basicList = event.getGeneration().getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION);
            basicList.add(()-> ExampleConfigFeature.TreeConfig.withPlacement(Features.Placements.HEIGHTMAP_PLACEMENT).withPlacement(Placement.COUNT_EXTRA.configure(
                    new AtSurfaceWithExtraConfig(1,0.11f,2)
            )));
        }
    }
}
